﻿using System;
using UnityEngine;

namespace Assets.Scripts.DynamicClouds
{
	// Token: 0x0200028E RID: 654
	public class Clouds : MonoBehaviour
	{
		// Token: 0x06000E77 RID: 3703 RVA: 0x0006FE2C File Offset: 0x0006E02C
		private void Awake()
		{
			this.CPEditMain = this.CloudParticles.main;
			this.CPEditShape = this.CloudParticles.shape;
			this.CPEditEmission = this.CloudParticles.emission;
			this.SetConstraints();
			this.SetElasticityOnOff();
			this.SetElasticityFactor();
			this.SetElasticityTolerance();
			this.SetParticleSize();
			this.SetParticleShape();
			this.SetTestMode();
		}

		// Token: 0x06000E78 RID: 3704 RVA: 0x0006FE98 File Offset: 0x0006E098
		public void SetConstraints()
		{
			this.Rbody.constraints = RigidbodyConstraints.None;
			if (GameController.cloudController.LockCloudTileElevation)
			{
				this.Rbody.constraints = RigidbodyConstraints.FreezePositionY;
			}
			if (GameController.cloudController.LockCloudTileRotation)
			{
				this.Rbody.constraints = RigidbodyConstraints.FreezeRotation;
			}
		}

		// Token: 0x06000E79 RID: 3705 RVA: 0x0006FEE8 File Offset: 0x0006E0E8
		public void SetElasticityOnOff()
		{
			this.DisableCloudElasticity = GameController.cloudController.DisableCloudElastisity;
		}

		// Token: 0x06000E7A RID: 3706 RVA: 0x0006FEFA File Offset: 0x0006E0FA
		public void SetPushLimitOnOff()
		{
			this.LimitCloudPush = GameController.cloudController.LimitCloudpush;
		}

		// Token: 0x06000E7B RID: 3707 RVA: 0x0006FF0C File Offset: 0x0006E10C
		public void SetElasticityFactor()
		{
			this.CloudElasticityFactor = GameController.cloudController.CloudElastisityFactor;
		}

		// Token: 0x06000E7C RID: 3708 RVA: 0x0006FF1E File Offset: 0x0006E11E
		public void SetElasticityTolerance()
		{
			this.PositionTolerence = GameController.cloudController.CloudElastisityPositionTolerence;
		}

		// Token: 0x06000E7D RID: 3709 RVA: 0x0006FF30 File Offset: 0x0006E130
		public void SetPushLimitDistance()
		{
			this.PositionMaxLimit = GameController.cloudController.CloudElastisityPositionMaxLimit * (GameController.cloudController.CloudScale * 2f);
			this.mXLimitMax = this.Origin.x + this.PositionMaxLimit;
			this.mXLimitMin = this.Origin.x - this.PositionMaxLimit;
			this.mYLimitMax = this.Origin.y + this.PositionMaxLimit;
			this.mYLimitMin = this.Origin.y - this.PositionMaxLimit;
			this.mZLimitMax = this.Origin.z + this.PositionMaxLimit;
			this.mZLimitMin = this.Origin.z - this.PositionMaxLimit;
		}

		// Token: 0x06000E7E RID: 3710 RVA: 0x0006FFEE File Offset: 0x0006E1EE
		public void SetParticleSize()
		{
			this.CPEditMain.startSize = new ParticleSystem.MinMaxCurve(0.75f * GameController.cloudController.CloudScale, 5f * GameController.cloudController.CloudScale);
		}

		// Token: 0x06000E7F RID: 3711 RVA: 0x00070020 File Offset: 0x0006E220
		public void SetParticleShape()
		{
			this.CPEditShape.scale = new Vector3(GameController.cloudController.CloudScale * 2f, GameController.cloudController.CloudScale * 2f, GameController.cloudController.CloudScale * 2f);
		}

		// Token: 0x06000E80 RID: 3712 RVA: 0x00070070 File Offset: 0x0006E270
		public void SetGtsAirCpompressionFactor(float size)
		{
			if (GameController.cloudController.GtsAirComressionFactor > 0f)
			{
				this.GtsColider.gameObject.SetActive(true);
				this.GtsColider.radius = GameController.cloudController.GtsAirComressionFactor * size;
			}
			else
			{
				this.GtsColider.gameObject.SetActive(false);
			}
		}

		// Token: 0x06000E81 RID: 3713 RVA: 0x000700D0 File Offset: 0x0006E2D0
		public void SetTestMode()
		{
			if (GameController.cloudController.UseTestVisuals)
			{
				this.TestVisuals.SetActive(true);
				this.CloudParticles.gameObject.SetActive(false);
				this.TestVisuals.transform.localScale = new Vector3(GameController.cloudController.CloudScale * 2f, GameController.cloudController.CloudScale * 2f, GameController.cloudController.CloudScale * 2f);
			}
			else
			{
				this.TestVisuals.SetActive(false);
				this.CloudParticles.gameObject.SetActive(true);
			}
		}

		// Token: 0x06000E82 RID: 3714 RVA: 0x00070170 File Offset: 0x0006E370
		public void InitializeCloudTile(float tileSize, Vector3 localOrigin)
		{
			this.Origin = localOrigin;
			this.MainCollider.radius = GameController.cloudController.CloudScale * 0.95f;
			this.SetGtsAirCpompressionFactor(tileSize);
			this.SetPushLimitDistance();
			this.SetPushLimitOnOff();
		}

		// Token: 0x06000E83 RID: 3715 RVA: 0x000701A7 File Offset: 0x0006E3A7
		public void setLOD(int level)
		{
			this.CPEditMain.maxParticles = this.ParticleMaxPerLOD[level];
			this.CPEditEmission.rateOverTime = this.ParticleRatePerLOD[level];
		}

		// Token: 0x06000E84 RID: 3716 RVA: 0x000701D4 File Offset: 0x0006E3D4
		private void LateUpdate()
		{
			if (this.LimitCloudPush)
			{
				base.transform.localPosition = new Vector3(Mathf.Clamp(base.transform.localPosition.x, this.mXLimitMin, this.mXLimitMax), Mathf.Clamp(base.transform.localPosition.y, this.mYLimitMin, this.mYLimitMax), Mathf.Clamp(base.transform.localPosition.z, this.mZLimitMin, this.mZLimitMax));
			}
			if (!this.DisableCloudElasticity && Vector3.Distance(base.transform.localPosition, this.Origin) > this.PositionTolerence)
			{
				base.transform.localPosition = Vector3.Lerp(base.transform.localPosition, this.Origin, this.CloudElasticityFactor);
			}
		}

		// Token: 0x04001389 RID: 5001
		public GameObject ShadowDetector;

		// Token: 0x0400138A RID: 5002
		public CloudShadowDetector ShadowDetectorScript;

		// Token: 0x0400138B RID: 5003
		public int[] ParticleMaxPerLOD;

		// Token: 0x0400138C RID: 5004
		public float[] ParticleRatePerLOD;

		// Token: 0x0400138D RID: 5005
		public bool DisableCloudElasticity;

		// Token: 0x0400138E RID: 5006
		public bool LimitCloudPush;

		// Token: 0x0400138F RID: 5007
		public float CloudElasticityFactor;

		// Token: 0x04001390 RID: 5008
		public float PositionTolerence;

		// Token: 0x04001391 RID: 5009
		public float PositionMaxLimit;

		// Token: 0x04001392 RID: 5010
		public SphereCollider GtsColider;

		// Token: 0x04001393 RID: 5011
		public SphereCollider MainCollider;

		// Token: 0x04001394 RID: 5012
		public ParticleSystem CloudParticles;

		// Token: 0x04001395 RID: 5013
		public ParticleSystem.MainModule CPEditMain;

		// Token: 0x04001396 RID: 5014
		public ParticleSystem.ShapeModule CPEditShape;

		// Token: 0x04001397 RID: 5015
		public ParticleSystem.EmissionModule CPEditEmission;

		// Token: 0x04001398 RID: 5016
		public GameObject TestVisuals;

		// Token: 0x04001399 RID: 5017
		public Rigidbody Rbody;

		// Token: 0x0400139A RID: 5018
		public Vector3 Origin;

		// Token: 0x0400139B RID: 5019
		private float mXLimitMax;

		// Token: 0x0400139C RID: 5020
		private float mYLimitMax;

		// Token: 0x0400139D RID: 5021
		private float mZLimitMax;

		// Token: 0x0400139E RID: 5022
		private float mXLimitMin;

		// Token: 0x0400139F RID: 5023
		private float mYLimitMin;

		// Token: 0x040013A0 RID: 5024
		private float mZLimitMin;
	}
}
